//
//  UITextField+PlaceholderExtension.m
//  快医
//
//  Created by 胥鸿儒 on 16/7/5.
//  Copyright © 2016年 xuhongru. All rights reserved.
//

#import "UITextField+PlaceholderExtension.h"

@implementation UITextField (PlaceholderExtension)


- (void)setupPlaceholderAttributes:(NSDictionary *)attributes placeholder:(NSString *)placeholder
{
    if (!placeholder) return;
    NSMutableParagraphStyle *style = [self.defaultTextAttributes[NSParagraphStyleAttributeName] mutableCopy];
    
    style.minimumLineHeight = self.font.lineHeight - (self.font.lineHeight - [UIFont systemFontOfSize:14.0].lineHeight) * 0.5;
    NSMutableDictionary *attributeDict = [NSMutableDictionary dictionaryWithDictionary:attributes];
    attributeDict[NSParagraphStyleAttributeName] = style;
    
    self.attributedPlaceholder = [[NSAttributedString alloc] initWithString:placeholder attributes:attributeDict.copy];
}

@end
